import Vue from "vue";
import VueI18n from "vue-i18n";
import enUS from "./locales/enUS";
import zhCN from "./locales/zhCN";
import qs from "querystring";
import {
  Modal,
  Button,
  Layout,
  Breadcrumb,
  Icon,
  Table,
  Pagination,
  Drawer,
  Radio,
  Menu,
  Form,
  Input,
  Select,
  LocaleProvider,
  Dropdown,
  DatePicker,
  FormModel,
  Checkbox,
  Tree,
  Badge,
  // Grid,
} from "ant-design-vue";
import VueHighlightjs from "vue-highlightjs";
import "highlight.js/styles/github.css";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import Authorized from "./components/Authorized.vue";
import Auth from "./directives/auth";
import "./styles/index.less";
import { TableSearch } from "@/components/default-table";
import * as echarts from "echarts";

Vue.config.productionTip = false;

Vue.use(Modal);
Vue.use(Button);
Vue.use(Layout);
Vue.use(Breadcrumb);
Vue.use(Icon);
Vue.use(Table);
Vue.use(Pagination);
Vue.use(Drawer);
Vue.use(Radio);
Vue.use(Menu);
Vue.use(Form);
Vue.use(Input);
Vue.use(Select);
Vue.use(LocaleProvider);
Vue.use(Dropdown);
Vue.use(DatePicker);
Vue.use(VueI18n);
Vue.use(VueHighlightjs);
Vue.use(FormModel);
Vue.use(Checkbox);
Vue.use(Tree);
Vue.use(Badge);
// Vue.use(Grid);

const i18n = new VueI18n({
  locale: qs.parse(location.search.locale || "zhCN"),
  messages: {
    zhCN: { message: zhCN },
    enUS: { message: enUS },
  },
});

Vue.component("Authorized", Authorized);
Vue.component("TableSearch", TableSearch);
Vue.use(Auth);

const IconFont = Icon.createFromIconfontCN({
  scriptUrl: "//at.alicdn.com/t/font_1154049_w87h4oeytph.js",
});

Vue.component("IconFont", IconFont);

Vue.prototype.$echarts = echarts;

let vue = new Vue({
  i18n,
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");

router.beforeEach((to, from, next) => {
  // _this.$dispash('user/Breadcrumb', to.matched)
  vue.$store.dispatch("user/Breadcrumb", to.matched);
  next();
});
